package com.burstly.lib.conveniencelayer;

import android.app.Activity;
import android.os.Looper;
import android.support.v4.app.Fragment;
import android.view.ViewGroup.LayoutParams;
import com.burstly.lib.conveniencelayer.events.AdCacheEvent;
import com.burstly.lib.conveniencelayer.events.AdClickEvent;
import com.burstly.lib.conveniencelayer.events.AdDismissFullscreenEvent;
import com.burstly.lib.conveniencelayer.events.AdFailEvent;
import com.burstly.lib.conveniencelayer.events.AdHideEvent;
import com.burstly.lib.conveniencelayer.events.AdPresentFullscreenEvent;
import com.burstly.lib.conveniencelayer.events.AdShowEvent;
import com.burstly.lib.ui.AdSize;
import com.burstly.lib.ui.BurstlyView;
import com.burstly.lib.ui.IBurstlyAdListener;
import com.burstly.lib.util.LoggerExt;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public abstract class BurstlyBaseAd
{
  protected static LoggerExt sLog = LoggerExt.getInstance();
  protected Activity mActivity;
  private IActivityListener mActivityListener = new IActivityListener()
  {
    public void activityDestroyed(Activity paramAnonymousActivity)
    {
      BurstlyBaseAd.this.destroyed();
    }

    public void activityPaused(Activity paramAnonymousActivity)
    {
      BurstlyBaseAd.this.paused();
    }

    public void activityResumed(Activity paramAnonymousActivity)
    {
      BurstlyBaseAd.this.resumed();
    }
  };
  protected BurstlyAdSize mAdSize;
  private IBurstlyAdListener mBurstlyAdListener = new IBurstlyAdListener()
  {
    public void adNetworkDismissFullScreen(String paramAnonymousString)
    {
      BurstlyBaseAd.this.onDismissFullscreen(new AdDismissFullscreenEvent(BurstlyBaseAd.this.mLastShow, false));
      BurstlyBaseAd.this.mLastShow = null;
    }

    public void adNetworkPresentFullScreen(String paramAnonymousString)
    {
      BurstlyBaseAd.this.onPresentFullscreen(new AdPresentFullscreenEvent(false));
    }

    public void adNetworkWasClicked(String paramAnonymousString)
    {
      BurstlyBaseAd.this.onClick(new AdClickEvent(paramAnonymousString));
    }

    public void attemptingToLoad(String paramAnonymousString)
    {
      BurstlyBaseAd.this.tryToLoadCreative(paramAnonymousString);
    }

    public void didLoad(String paramAnonymousString, boolean paramAnonymousBoolean)
    {
      if (BurstlyBaseAd.this.mLastShow != null);
      for (boolean bool = true; ; bool = false)
      {
        if (bool)
          BurstlyBaseAd.this.onHide(new AdHideEvent(true, BurstlyBaseAd.this.mLastShow));
        BurstlyBaseAd.this.mLastShow = new AdShowEvent(paramAnonymousBoolean, paramAnonymousString, BurstlyBaseAd.this.mFailedCreativesList, bool);
        BurstlyBaseAd.this.onShow(BurstlyBaseAd.this.mLastShow);
        if ((BurstlyBaseAd.this.mAdSize.isInterstitial()) || (!paramAnonymousBoolean))
          break;
        throw new IllegalStateException("You are using interstitial ads in " + BurstlyBaseAd.this.getName() + " banner view");
      }
      if ((BurstlyBaseAd.this.mAdSize.isInterstitial()) && (!paramAnonymousBoolean))
        throw new IllegalStateException("You are using banner ads in " + BurstlyBaseAd.this.getName() + " interstitial view");
    }

    public void didPrecacheAd(String paramAnonymousString)
    {
      BurstlyBaseAd.this.mLastCache = new AdCacheEvent(paramAnonymousString, BurstlyBaseAd.this.mFailedCreativesList);
      BurstlyBaseAd.this.onCache(BurstlyBaseAd.this.mLastCache);
    }

    public void failedToDisplayAds()
    {
      if (BurstlyBaseAd.this.mCachingState == BurstlyBaseAd.CachingState.Retrieving);
      for (boolean bool = true; ; bool = false)
      {
        BurstlyBaseAd.this.onFail(new AdFailEvent(BurstlyBaseAd.this.mFailedCreativesList, BurstlyBaseAd.this.mBurstlyView, bool));
        return;
      }
    }

    public void failedToLoad(String paramAnonymousString)
    {
      BurstlyBaseAd.this.singleCreativeFailed(paramAnonymousString);
    }

    public void finishRequestToServer()
    {
    }

    public void onCollapse()
    {
      BurstlyBaseAd.this.onDismissFullscreen(new AdDismissFullscreenEvent(BurstlyBaseAd.this.mLastShow, true));
    }

    public void onExpand(boolean paramAnonymousBoolean)
    {
      BurstlyBaseAd.this.onPresentFullscreen(new AdPresentFullscreenEvent(true));
    }

    public void onHide()
    {
    }

    public void onShow()
    {
    }

    public void requestThrottled(int paramAnonymousInt)
    {
      if (BurstlyBaseAd.this.mCachingState == BurstlyBaseAd.CachingState.Retrieving);
      for (boolean bool = true; ; bool = false)
      {
        BurstlyBaseAd.this.onFail(new AdFailEvent(paramAnonymousInt, bool));
        return;
      }
    }

    public void startRequestToServer()
    {
      BurstlyBaseAd.this.requestStarted();
    }

    public void viewDidChangeSize(AdSize paramAnonymousAdSize1, AdSize paramAnonymousAdSize2)
    {
    }
  };
  private BurstlyView mBurstlyView;
  protected CachingState mCachingState = CachingState.Idle;
  protected String mCurrentCreative;
  protected ArrayList<String> mFailedCreativesList;
  protected Fragment mFragment;
  private IFragmentListener mFragmentListener = new IFragmentListener()
  {
    public void fragmentDestroyed(Fragment paramAnonymousFragment)
    {
      BurstlyBaseAd.this.destroyed();
    }

    public void fragmentPaused(Fragment paramAnonymousFragment)
    {
      BurstlyBaseAd.this.paused();
    }

    public void fragmentResumed(Fragment paramAnonymousFragment)
    {
      BurstlyBaseAd.this.resumed();
    }
  };
  protected AdCacheEvent mLastCache;
  protected AdShowEvent mLastShow;
  protected final List<IBurstlyListener> mListeners = new ArrayList();

  protected BurstlyBaseAd(Activity paramActivity, BurstlyAdSize paramBurstlyAdSize)
  {
    this.mActivity = paramActivity;
    this.mAdSize = paramBurstlyAdSize;
  }

  protected BurstlyBaseAd(Fragment paramFragment, BurstlyAdSize paramBurstlyAdSize)
  {
    this.mFragment = paramFragment;
    this.mAdSize = paramBurstlyAdSize;
  }

  private void setCrids(Map<String, Object> paramMap)
  {
    if (Burstly.isIntegrationModeEnabledForThisDevice());
    try
    {
      Class[] arrayOfClass = { Map.class };
      Method localMethod = this.mBurstlyView.getClass().getDeclaredMethod("setCridParams", arrayOfClass);
      localMethod.setAccessible(true);
      localMethod.invoke(this.mBurstlyView, new Object[] { paramMap });
      return;
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      localNoSuchMethodException.printStackTrace();
      return;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      localIllegalArgumentException.printStackTrace();
      return;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      localIllegalAccessException.printStackTrace();
      return;
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      localInvocationTargetException.printStackTrace();
    }
  }

  protected static void throwIfNotOnMainThread()
  {
    if (Thread.currentThread() != Looper.getMainLooper().getThread())
      throw new RuntimeException("com.burstly.convenience.Banner must be called from the ui thread");
  }

  public void addBurstlyListener(IBurstlyListener paramIBurstlyListener)
  {
    try
    {
      this.mListeners.add(paramIBurstlyListener);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  protected void baseCacheAd()
  {
    sLog.logWarning("Burstly Convenience Layer", "cacheAd start", new Object[0]);
    if (baseHasCachedAd())
    {
      LoggerExt localLoggerExt = sLog;
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = getName();
      localLoggerExt.logWarning("Burstly Convenience Layer", "{0}: Ad already cached.", arrayOfObject);
      onCache(this.mLastCache);
    }
    while (true)
    {
      sLog.logWarning("Burstly Convenience Layer", "cacheAd end", new Object[0]);
      return;
      throwIfNotOnMainThread();
      this.mCachingState = CachingState.Retrieving;
      this.mBurstlyView.precacheAd();
    }
  }

  protected boolean baseHasCachedAd()
  {
    if ((this.mBurstlyView == null) || (this.mBurstlyView.isCachedAdExpired() == null));
    while ((this.mCachingState != CachingState.Retrieved) || (this.mBurstlyView.isCachedAdExpired().booleanValue()))
      return false;
    return true;
  }

  protected boolean baseIsCachingAd()
  {
    return this.mCachingState == CachingState.Retrieving;
  }

  protected void destroyed()
  {
    throwIfNotOnMainThread();
    this.mBurstlyView.destroy();
  }

  public String getAdParameters()
  {
    return this.mBurstlyView.getCrParms();
  }

  public String getAppId()
  {
    return this.mBurstlyView.getPublisherId();
  }

  protected BurstlyView getBurstlyView()
  {
    return this.mBurstlyView;
  }

  public Map<String, ?> getCustomParamsForNetwork(String paramString)
  {
    return this.mBurstlyView.getCustomParamsForNetwork(paramString);
  }

  public String getName()
  {
    return this.mBurstlyView.getBurstlyViewId();
  }

  public String getTargetingParameters()
  {
    return this.mBurstlyView.getPubTargetingParams();
  }

  public String getZoneId()
  {
    return this.mBurstlyView.getZoneId();
  }

  public boolean isPausedRefresh()
  {
    return this.mBurstlyView.isPaused();
  }

  protected void onCache(AdCacheEvent paramAdCacheEvent)
  {
    this.mCachingState = CachingState.Retrieved;
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onCache(this, paramAdCacheEvent);
  }

  protected void onClick(AdClickEvent paramAdClickEvent)
  {
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onClick(this, paramAdClickEvent);
  }

  protected void onDismissFullscreen(AdDismissFullscreenEvent paramAdDismissFullscreenEvent)
  {
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onDismissFullscreen(this, paramAdDismissFullscreenEvent);
  }

  protected void onFail(AdFailEvent paramAdFailEvent)
  {
    this.mCachingState = CachingState.Idle;
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onFail(this, paramAdFailEvent);
  }

  protected void onHide(AdHideEvent paramAdHideEvent)
  {
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onHide(this, paramAdHideEvent);
    this.mLastShow = null;
  }

  protected void onPresentFullscreen(AdPresentFullscreenEvent paramAdPresentFullscreenEvent)
  {
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onPresentFullscreen(this, paramAdPresentFullscreenEvent);
  }

  protected void onShow(AdShowEvent paramAdShowEvent)
  {
    this.mCachingState = CachingState.Idle;
    Iterator localIterator = this.mListeners.iterator();
    while (localIterator.hasNext())
      ((IBurstlyListener)localIterator.next()).onShow(this, paramAdShowEvent);
  }

  public void pauseRefresh()
  {
    this.mBurstlyView.setPaused(true);
  }

  protected void paused()
  {
    throwIfNotOnMainThread();
    this.mBurstlyView.onHideActivity();
    if (this.mCachingState == CachingState.Retrieving)
      this.mCachingState = CachingState.Idle;
  }

  public void removeBurstlyListener(IBurstlyListener paramIBurstlyListener)
  {
    try
    {
      this.mListeners.remove(paramIBurstlyListener);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  protected void requestStarted()
  {
    this.mFailedCreativesList = new ArrayList();
  }

  public void resumeRefresh()
  {
    this.mBurstlyView.setPaused(false);
  }

  protected void resumed()
  {
    throwIfNotOnMainThread();
    this.mBurstlyView.onShowActivity();
  }

  public void setAdParameters(String paramString)
  {
    this.mBurstlyView.setCrParms(paramString);
  }

  public void setBurstlyUserInfo(Map<String, String> paramMap)
  {
    this.mBurstlyView.setClientTargetParams(paramMap);
  }

  protected void setBurstlyView(BurstlyView paramBurstlyView)
  {
    throwIfNotOnMainThread();
    if (this.mBurstlyView != null)
      throw new RuntimeException("BurstlyView cannot be changed.");
    this.mBurstlyView = paramBurstlyView;
    this.mBurstlyView.setPublisherId(Burstly.getAppID());
    this.mBurstlyView.setBurstlyAdListener(this.mBurstlyAdListener);
    BurstlyIntegrationModeAdNetworks localBurstlyIntegrationModeAdNetworks = Burstly.getIntegrationNetwork();
    String str;
    if (Burstly.isIntegrationModeEnabledForThisDevice())
    {
      sLog.logDebug("Burstly Convenience Layer", "Device is Test Device.", new Object[0]);
      if (localBurstlyIntegrationModeAdNetworks != BurstlyIntegrationModeAdNetworks.DISABLED)
      {
        LoggerExt localLoggerExt = sLog;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = getName();
        localLoggerExt.logDebug("Burstly Convenience Layer", "Ad {0} will display sample ads from specified ad network.", arrayOfObject);
        BurstlyView localBurstlyView = this.mBurstlyView;
        if (this.mAdSize.isInterstitial())
        {
          str = localBurstlyIntegrationModeAdNetworks.getInterstitialZone();
          localBurstlyView.setZoneId(str);
          this.mBurstlyView.setPublisherId(BurstlyIntegrationModeAdNetworks.getAppId());
        }
      }
      else
      {
        if (this.mActivity == null)
          break label193;
        Burstly.showTestModeAlert(this.mActivity);
      }
    }
    while (true)
    {
      if (this.mActivity == null)
        break label232;
      Burstly.addActivityListener(this.mActivity, this.mActivityListener);
      return;
      str = localBurstlyIntegrationModeAdNetworks.getBannerZone();
      break;
      label193: if (this.mFragment != null)
      {
        Burstly.showTestModeAlert(this.mFragment.getActivity());
        continue;
        sLog.logDebug("Burstly Convenience Layer", "Device is not a test device. Using default pub and zone.", new Object[0]);
      }
    }
    label232: Burstly.addFragmentListener(this.mFragment, this.mFragmentListener);
  }

  public void setCustomParamsForNetwork(String paramString, Map<String, ?> paramMap)
  {
    this.mBurstlyView.setCustomParamsForNetwork(paramString, paramMap);
  }

  public void setLayoutParams(ViewGroup.LayoutParams paramLayoutParams)
  {
    if (paramLayoutParams != null)
      this.mBurstlyView.setLayoutParams(paramLayoutParams);
  }

  public void setTargetingParameters(String paramString)
  {
    this.mBurstlyView.setPubTargetingParams(paramString);
  }

  public void showAd()
  {
    throwIfNotOnMainThread();
    this.mBurstlyView.setAdSize(this.mAdSize);
    this.mBurstlyView.setInterstitalMode(this.mAdSize.isInterstitial());
    this.mBurstlyView.sendRequestForAd();
  }

  public void showAd(Map<String, Object> paramMap)
  {
    setCrids(paramMap);
    showAd();
  }

  protected void singleCreativeFailed(String paramString)
  {
    this.mFailedCreativesList.add(paramString);
  }

  protected void tryToLoadCreative(String paramString)
  {
    this.mCurrentCreative = paramString;
  }

  protected static enum CachingState
  {
    static
    {
      Retrieved = new CachingState("Retrieved", 2);
      CachingState[] arrayOfCachingState = new CachingState[3];
      arrayOfCachingState[0] = Idle;
      arrayOfCachingState[1] = Retrieving;
      arrayOfCachingState[2] = Retrieved;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.conveniencelayer.BurstlyBaseAd
 * JD-Core Version:    0.6.2
 */